#include <sys/types.h>
#include <sys/stat.h>
#include <stdint.h>
#include <time.h>
#include <sys/sysmacros.h>
#include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>


int fileModel(const struct stat sb){
    return sb.st_mode & S_IFMT;
}


void printFile(const char *name){
    struct stat sb;
    if (lstat(name, &sb) == -1) {
        perror("lstat");
    } else{
        if (fileModel(sb) == S_IFDIR){
            DIR *dp;
            struct dirent *sdp;
            dp = opendir(name);
            while((sdp = readdir(dp)) !=NULL){
                if(strcmp(sdp->d_name,".") == 0 || strcmp(sdp->d_name,"..") == 0) {
                    continue;
                }
                char filename[256] = {};
                strcat(filename,name);
                strcat(filename,"/");
                strcat(filename,sdp->d_name);
                printFile(filename);
            }
            closedir(dp);
        }
        printf("%-20s       %jd\n",name, (intmax_t)sb.st_size);
    }
}



int main(int argc, char *argv[]) {
    if (argc != 2) {
        fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    printFile(argv[1]);
    return 0;
}